package com.burgeon.backend.SHOPBACKEND.rest.weixin;
/**
 * 创建VIP聊天记录
 */


import com.burgeon.backend.Rest.base.RESTBase;
import com.burgeon.backend.entity.VipAttrib;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

public class VipAppCode extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public VipAppCode(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     */

    public String getData(String cVipIdCardNo,String type,String employeeName,String hrOpenid,String state,String content) throws Exception {
        String url = "http://" + ip + "/servlets/binserv/Rest";

        String str = RESULT(Data(cVipIdCardNo,type,employeeName,hrOpenid,state,content), url);

        //System.err.println(str);
        String code = new JSONArray(str).getJSONObject(0).getString("code");
        String message= new JSONArray(str).getJSONObject(0).getString("message");
        //System.err.println(code);
        if (!"0".equals(code)) {
            throw new Exception("创建失败"+message);
        }
        return code;
    }

    private MultiValueMap Data(String cVipIdCardNo,String type,String employeeName,String hrOpenid,String state,
                               String content) {

        HashMap params = new HashMap();

        params.put("C_VIP_ID__CARDNO",cVipIdCardNo);//所属VIP
        params.put("TYPE",type);	//	类型(发出/接收)
        params.put("HR_EMPLOYEE_ID__NAME",employeeName);//	员工/导购
        params.put("HR_OPENID",hrOpenid);	//	导购OPENID
        params.put("STATE",state);//	发送状态
        params.put("CONTENT","'"+content+"'");//	消息内容


//        Date now = new Date();
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
//        String dateString = sdf.format(now);
//
//
//        params.put("CREAT_TIME",dateString);	//	消息创建时间

        params.put("table", "APP_VIP_CHATRECORD");//表名
        //System.err.println(params);

        return DATA("ObjectCreate", params, account, password);
    }

    public static void main(String[] args) {
    /*    VipAppCode g = new VipAppCode("59.110.28.94:90", "nea@burgeon.com.cn", "burgeon55321");
        try {
            VipAttrib vipAttrib = new VipAttrib();
            vipAttrib.setVipAttrib2("120-140");
            g.getData("17732145129",vipAttrib);
        } catch (Exception e) {
            e.printStackTrace();
        }*/
    }
}
